
//
//  LSContactListTableViewCell.m
//  LaSaCivilAffairsDepartment
//
//  Created by 聂志康 on 2019/2/12.
//  Copyright © 2019 wpkj. All rights reserved.
//

#import "LSContactListTableViewCell.h"

#define rightImageWidth 21

@interface LSContactListTableViewCell ()
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *phoneLabel;
@property (nonatomic, strong) UIImageView *rightImageView;
@end

@implementation LSContactListTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self.contentView addSubview:self.rightImageView];
        [self.contentView addSubview:self.nameLabel];
        [self.contentView addSubview:self.phoneLabel];
    }
    return self;
}

- (void)setDataDict:(NSDictionary *)dataDict {
    _dataDict = dataDict;
    self.nameLabel.text = [ValidateUtils validateNull:dataDict[@"name"]];
    self.phoneLabel.text = [ValidateUtils validateNull:dataDict[@"phone"]];
}

- (void)setName:(NSString *)name {
    _name = name;
    self.nameLabel.text = name;
}

- (void)setPhone:(NSString *)phone {
    _phone = phone;
    self.phoneLabel.text = phone;
}

- (void)setRightImageName:(NSString *)rightImageName {
    _rightImageName = rightImageName;
    self.rightImageView.image = [UIImage imageNamed:rightImageName];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    WS
    [self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView.mas_left).with.offset(15);
        make.top.equalTo(weakSelf.contentView.mas_top).with.offset(10);
        make.right.equalTo(weakSelf.rightImageView.mas_left).with.offset(-12);
    }];
    [self.phoneLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView.mas_left).with.offset(15);
        make.top.equalTo(weakSelf.contentView.mas_centerY).with.offset(2);
        make.right.equalTo(weakSelf.rightImageView.mas_left).with.offset(-12);
    }];
    [self.rightImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.contentView.mas_right).with.offset(-12);
        make.centerY.equalTo(weakSelf.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(rightImageWidth, rightImageWidth));
    }];
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:14];
        _nameLabel.textColor = hexColor(333333);
    }
    return _nameLabel;
}

- (UILabel *)phoneLabel {
    if (!_phoneLabel) {
        _phoneLabel = [[UILabel alloc] init];
        _phoneLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:12];
        _phoneLabel.textColor = hexColor(444444);
    }
    return _phoneLabel;
}

- (UIImageView *)rightImageView {
    if (!_rightImageView) {
        _rightImageView = [[UIImageView alloc] init];
        _rightImageView.contentMode = UIViewContentModeScaleAspectFit;
        _rightImageView.image = [UIImage imageNamed:@"icon电话"];
    }
    return _rightImageView;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
